﻿Imports util
Imports System.Data.SqlServerCe
Imports System.Data.OleDb

Public Class Form1

    Public dni As String
    Public cod As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        


        'MsgBox(contexto.RUTA_BD)
        txtRutaPersonal.Text = contexto.RUTA_DATA

        cod = contexto.configuracionService.getCodigo()

        Dim lista As New ListaItems
        lista.agregar("01", "1")
        lista.agregar("02", "2")
        lista.agregar("03", "3")
        lista.agregar("04", "4")
        lista.agregar("05", "5")
        lista.agregar("06", "6")
        cboAula.Items.AddRange(lista.toArray())

        Dim lista2 As New ListaItems
        lista2.agregar("01", "PC 1")
        lista2.agregar("02", "PC 2")
        lista2.agregar("03", "PC 3")
        lista2.agregar("04", "PC 4")
        lista2.agregar("05", "PC 5")
        lista2.agregar("06", "PC 6")
        lista2.agregar("07", "PC 7")
        lista2.agregar("08", "PC 8")
        lista2.agregar("09", "PC 9")
        lista2.agregar("10", "PC 10")
        lista2.agregar("11", "PC 11")
        lista2.agregar("12", "PC 12")
        lista2.agregar("13", "PC 13")
        lista2.agregar("14", "PC 14")
        lista2.agregar("15", "PC 15")
        lista2.agregar("16", "PC 16")
        lista2.agregar("17", "PC 17")
        lista2.agregar("18", "PC 18")
        lista2.agregar("19", "PC 19")
        lista2.agregar("20", "PC 20")
        'cboPC.Items.AddRange(lista2.ToArray())

        If Not cod = "" Then
            Dim aula As String = cod.Substring(0, 2)
            dni = cod.Substring(3, 8)

            'MsgBox(aula & "-" & lista.getIndiceItemByValor(aula))
            'MsgBox(pc & "-" & lista.getIndiceItemByValor(pc))

            cboAula.SelectedIndex = lista.getIndiceItemByValor(aula)
            'cboPC.SelectedIndex = lista2.getIndiceItemByValor(pc)
            txtDni.Text = dni
        End If

        'temporal
        'FrmAdminPersonal.Show()

        'FrmAdmin.Show()
    End Sub



    Private Sub btnPersonal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPersonal.Click
        Dim v1 As Item = cboAula.SelectedItem
        'Dim v2 As Item = cboPC.SelectedItem
        Dim v2 As String = txtDni.Text

        If v1 Is Nothing Then
            MsgBox("Debe seleccionar un aula")
        ElseIf v2 = "" Or v2.Length < 8 Then
            MsgBox("Escriba un DNI de 8 digitos")
        Else
            Try
                cod = v1.valor & "-" & v2
                contexto.configuracionService.guardarCodigo(cod)

                dni = v2
                'Me.Hide() ' para poder cerrar la aplicacion
                FrmAdminPersonal.ShowDialog()
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try

        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim clave As String = contexto.CLAVE
        'Dim clave As String = "enahouser"

        If txtClave.Text = clave Then
            Me.Hide()
            FrmAdmin.Show()
        Else
            MsgBox("No tiene permisos para esta opción")
        End If
    End Sub

    Private Sub btnSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalir.Click
        If MessageBox.Show("¿Está seguro que desea salir de la aplicación?", "Mensaje", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.Yes Then
            Me.Close()
        End If
    End Sub
End Class
